﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;

namespace ElValWeb.ValidatorClientAdapters {

    public abstract class BaseClientAdapter{

        public abstract IEnumerable<ModelClientValidationRule> GetClientRules(Type ownerType);

    }

   

    public abstract class BaseClientAdapter<T> : BaseClientAdapter where T : ValidatorData {

        protected T  ValidatorData;

        protected BaseClientAdapter(T validatorData) {
            ValidatorData = validatorData;
        }

        protected ModelClientValidationRule Negate(ModelClientValidationRule rule, bool doNegate) {
            if (!doNegate) {
                return rule;
            }

            var negatedRule = new ModelClientValidationRequiredRule(ValidatorData.GetMessageTemplate());
            negatedRule.ValidationType = "negateValidator";
            negatedRule.ValidationParameters["innerValidator"] = rule;

            return negatedRule;
        }
    }
}
